<?php
//王晓梦
declare (strict_types=1);

namespace app\backend\controller\v2;
use app\common\model\ExampleZan as ExampleZanZanModel;

class ExampleZan extends BaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $page = input('page/d', 1);
        $size = 10;
        //获取该分类下的数据
        $data = ExampleZanZanModel::where(['status' => 1])
            //模型关联
            ->with(['getmember', 'getexample'])
            ->order('id desc')
            ->page($page, $size)
            ->select();
        //统计数量
        $rows = count(ExampleZanZanModel::where('status', 1)
            ->select()
            ->toArray());
        $maxPage = ceil($rows / $size);
        foreach ($data as &$v) {
            if(empty($v->getmember)){
                $v['member_id'] = "暂无用户名";
            } else {
                $v['member_id'] = $v->getmember->account;
                unset($v->getmember);
                $v['example_id'] = $v->getexample->title;
                unset($v->getexample);
            }

        }
        return sucessMsg(200, '获取成功！', ['data' => $data, 'page' => $page, 'maxPage' => $maxPage, 'rows' => $rows]);
    }
}
